package com.eascs.admin.o2o.loan.notify.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.eascs.admin.o2o.internal.util.StatusContexts;
import com.eascs.admin.o2o.loan.entity.O2oLoanapplyEntity;
import com.eascs.admin.o2o.loan.notify.O2OMsgNotifyService;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.workflow.common.entity.wf.ProcessTaskMain;
import com.eascs.workflow.common.entity.wf.ProcessTemplate;
import com.eascs.workflow.common.vo.ModelResult;
import com.eascs.workflow.common.vo.WFNotifyParam;

/**
 * 面签申报流程
 */
@Service
public class MQSBMsgNotifyServiceImpl implements O2OMsgNotifyService {
	private static Logger log = LoggerFactory.getLogger(MQSBMsgNotifyServiceImpl.class);

	@Override
	public ModelResult<O2oLoanapplyEntity> notify(WFNotifyParam notifyParam, O2oLoanapplyEntity loanapply){
		ModelResult<O2oLoanapplyEntity> modelResult =new ModelResult<>();
		log.info("启动面签申报流程通知:[{}]", StatusContexts.WFTYPE_BRT);
		
		loanapply = sbFlow(notifyParam,loanapply);
		/*if (notifyParam.getProcessStatus() == ProcessTaskMain.PROECESS_STATUS_PASS) {
			log.info("归档流程通过记录通知：{}", loanapply.getBillCode());
			loanapply.setIsPlaceOnFile(StatusContexts.WFTYPE_STATUS_CLO);
			loanapply.setPlaceOnFileTime(new Date());
		} else if (notifyParam.getProcessStatus() == ProcessTaskMain.PROECESS_STATUS_TURNED_DOWN) {
			log.info("归档流程驳回记录通知：{}", loanapply.getBillCode());
			loanapply.setIsPlaceOnFile(StatusContexts.O2O_NEW);
		} else if (notifyParam.getProcessStatus().equals(ProcessTaskMain.PROECESS_STATUS_REJECT)) {
			log.info("归档流程作废记录通知：{}", loanapply.getBillCode());
		}*/
		modelResult.withModel(loanapply);
		return modelResult;
	}

	@Override
	public List<String> getServiceName() {
		ArrayList<String> list = new ArrayList<String>();
		list.add(ProcessTemplate.PROECESS_TYPE_BANK_REPORT);
		list.add(ProcessTemplate.PROECESS_TYPE_BANK_REPORT_FQ);
		return list;
	}
	
	
	@Override
	public Boolean checkReturn() {
		return Boolean.FALSE;
	}
	
	/**
	 * 申报流程
	 * 
	 * @param notifyParam
	 * @param loanapplyEntity
	 * @return
	 */
	private O2oLoanapplyEntity sbFlow(WFNotifyParam notifyParam, O2oLoanapplyEntity loanapplyEntity) {
		if (notifyParam.getProcessStatus() == ProcessTaskMain.PROECESS_STATUS_PASS) {
			/*
			 * String bank_type = loanapplyEntity.getBankLoanName(); //放款银行
			 * if(StatusContexts.O2O_BANKTYPE_BC.equals(bank_type)||
			 * StatusContexts.O2O_BANKTYPE_CCBHN.equals(bank_type)
			 * ||StatusContexts.O2O_BANKTYPE_CBC.equals(bank_type) ||
			 * StatusContexts.O2O_BANKTYPE_GACZ.equals(bank_type)){
			 * try{//面签申报完成之后发送短信 ModelResult<Boolean> messageResult =
			 * o2oMessageServiceImpl.mqsbMessage(loanapplyEntity.getBillCode());
			 * if(messageResult.getModel()){ //如果是返回的是true，说明是成功的 log.info(
			 * "billCode:[{}],面签申报 银行申报审查节点通过后给客户 发送通知短信成功"
			 * ,loanapplyEntity.getBillCode()); }else{ log.error(
			 * "billCode:[{}],面签申报 银行申报审查节点通过后给客户 发送通知短信失败"
			 * ,loanapplyEntity.getBillCode()); } }catch(Exception e){
			 * log.error("billCode:[{}],面签申报 银行申报审查节点通过后给客户 发送通知短信失败："
			 * ,loanapplyEntity.getBillCode()); } }
			 */
			log.info("贷款编号:[{}],申报流程完成,修改为主表状态为：[{}]", loanapplyEntity.getBillCode(), StatusContexts.O2O_FK_END);
			loanapplyEntity.setWfType(StatusContexts.O2O_FK_END);
		} else if (notifyParam.getProcessStatus() == ProcessTaskMain.PROECESS_STATUS_TURNED_DOWN) {
			log.info("贷款编号:[{}],申报流程驳回,修改为主表状态为：[{}]", loanapplyEntity.getBillCode(), StatusContexts.O2O_NS_END);
			loanapplyEntity.setWfType(StatusContexts.O2O_NS_END);
		} else if (notifyParam.getProcessStatus().equals(ProcessTaskMain.PROECESS_STATUS_REJECT)) {
			log.info("贷款编号:[{}],申报流程作废,修改为主表状态为：[{}]", loanapplyEntity.getBillCode(), StatusContexts.O2O_FK_OVER);
			loanapplyEntity.setWfType(StatusContexts.O2O_FK_OVER);
		}
		return loanapplyEntity;
	}
	
}
